/**
 * Copyright (c) 2022 Shanghai Fullhan Microelectronics Co., Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 *
 * Change Logs:
 */

#include <common.h>
#include <asm/io.h>
#include <asm/arch/hardware.h>

#define REG_SYS_TIMER_VALUE		(SYS_TIMER_REG_BASE + 0x4)
#define SYS_TIMER_CLK_FREQ			(1000000)	// syst_clk/32

ulong get_tbclk(void)
{
	return SYS_TIMER_CLK_FREQ;
}

uint64_t get_ticks(void)
{
	return (uint64_t)__raw_readl(REG_SYS_TIMER_VALUE);
}

static u32 get_sys_ticks(void)
{
	return (__raw_readl(REG_SYS_TIMER_VALUE));
}

void __udelay(unsigned long usec)
{
	u32 v;
	u32 v1,v2;
	v1 = get_sys_ticks();
	do
	{
		v2 = get_sys_ticks();
		v = v2 - v1;
	}while(v < usec);
}
